const powSum = (arr: number[]) => {
    let sum = 0
    arr.forEach((item: number) => sum += Math.pow(2, item))
    return sum
}

export enum AccountStatus {
    DISCARD = powSum([24]), //gray", "DISCARD", "已注销", "此账号已注销", ""),
    NUKE = powSum([22]), //darkred", "NUKED", "NUKED", "因违反版规而被禁用", "必须使用激活码解除"),
    LOCK = powSum([22, 23]), //gray", "LOCKED", "锁定(注)", "因违规注册或发布违规广告等情况而被禁用", "不能解锁"),
    MANUAL = powSum([21, 23]), //darkred", "LOCKED", "锁定(广)", "因账号被盗或发布违规广告等情况被禁用", "只能人工解锁 参阅版务区相关说明"),
    RESET = powSum([23]), //deeppink", "LOCKED", "锁定(安)", "因账号安全问题被禁用", "使用[邮箱重置密码]解锁, 或使用论坛app中的[忘记密码]重置密码解锁(绑定手机时间需在锁定时间之前)", "/nuke.php?__lib=login&__act=account&resetpass"),
    PASS = powSum([21, 22]), //sienna", "LOCKED", "锁定(安)", "因账号安全问题被禁用", "修改密码解锁", "/nuke.php?__lib=login&__act=account&changepass"),
    PHONE = powSum([20]), //seagreen", "ACTIVED", "已激活", "", "已绑定手机激活"),
    LINK = powSum([29]), //seagreen", "LINKED", "关联", "此账号关联到了其他的账号激活", ""),
    UN = -1, //orange", "UNACTIVED", "未激活", "账号未激活", "你可以在用户中心绑定手机激活"),
}

export const accountStatusDes = (status: AccountStatus) => {
    switch (status) {
        case AccountStatus.MANUAL:
            return "锁定(广)"
        case AccountStatus.PASS:
            return "锁定(安)"
        case AccountStatus.LOCK:
            return "锁定(注)"
        case AccountStatus.RESET:
            return "锁定(安)"
        case AccountStatus.DISCARD:
            return "已注销"
        case AccountStatus.NUKE:
            return "NUKED"
        case AccountStatus.PHONE:
            return "已激活"
        case AccountStatus.LINK:
            return "关联"
        case AccountStatus.UN:
            return "未激活"
        default:
            break;
    }
}

const bits = Object.values(AccountStatus).map(i => i as AccountStatus).filter(i => !isNaN(Number(i)));

export function buildAccountStatus(bitData: number): AccountStatus {
    return bits.find((it: number) => (it & bitData) == it) as AccountStatus || AccountStatus.UN;
}